//
//  CoverMaskView.m
//  XPhoto
//
//  Created by sentinel on 2020/4/3.
//  Copyright © 2020 baboy. All rights reserved.
//

#import "CoverMaskView.h"
@implementation CoverMaskView
+ (instancetype)newInstance{
    CoverMaskView *view = loadViewFromNib([self class], nil);
    return view;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect titleFrame = self.titleLabel.frame;
    CGSize titleSize = [self.titleLabel.text boundingRectWithSize:CGSizeMake(titleFrame.size.width, CGFLOAT_MAX)
                                                          options:NSStringDrawingUsesLineFragmentOrigin
                                                       attributes:@{NSFontAttributeName:self.titleLabel.font}
                                                          context:nil].size;
    titleFrame.size.height = titleSize.height;
    titleFrame.origin.y = self.userNameLabel.frame.origin.y - titleFrame.size.height;
    self.titleLabel.frame = titleFrame;
}
- (void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
    [self setNeedsLayout];
}
- (void)setUserName:(NSString *)userName{
    _userName = userName;
    self.userNameLabel.text = userName?[NSString stringWithFormat:@"@%@", userName]:nil;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
